﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class WithStatementExpression : StatementElement
    {
        private List<ExpressionElement> expressions;
        public StatementElement statement;

        public List<ExpressionElement> Expressions { get { return expressions; } set { expressions = value; } }
        public StatementElement Statement { get { return statement; } set { statement = value; } }

        public WithStatementExpression(TokenInfo StartInfo, List<ExpressionElement> Expressions, StatementElement Statement, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            expressions = Expressions;
            statement = Statement;
        }

        public override string ToString()
        {
            return string.Format("with {0} do {1}", expressions.Join(", "), statement);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (expressions != null)
                foreach (ExpressionElement expression in expressions)
                    yield return expression;
            yield return statement;
        }
    }
}
